<?php $divId = $this->uuid('div', $this->here); ?>
<div id="<?php echo $divId; ?>">
    <?php echo $ajax->form('Site', 'post', array('update'=> 'divSites', 'indicator' => 'indicator', 'url'=>array('action' => 'save_site'))); ?>
    <?php echo $form->input('Site.id'); ?>
    <?php echo $form->hidden('Site.customer_id', array('value' => $customer_id)); ?>
    <?php echo $form->hidden('mode', array('value' => $mode)); ?>

    <div class="toolbar">
        <?php if ($mode == 'add') : ?>
            <?php echo $this->element('toolbar', array('buttons' => array('save', array('clear' => array('update' => $divId))))); ?>
        <?php else : // mode edit ?>
            <?php echo $this->element('toolbar', array('buttons' => 
                array('save',
                    array('refresh_view' => array('model' => 'Site', 'action' => 'view_site/' . $this->data['Site']['id'], 'update' => $divId)),
                    array('delete' => array('controller' => 'its_customers', 'action' => 'delete_site', 'model' => 'Site', 'title' => 'name', 'update' => 'divSites')), 
                    'view_as_site_user'))); ?>
        <?php endif; ?>
    </div>
    <br />

    <fieldset>
        <legend>Site Information</legend>
        <table>
            <?php if ($mode == 'edit') : ?>
            <tr>
                <td width="120px"><?php echo $form->label('Site.site_no', 'Site no') ?></td>
                <td>
                        <?php echo $this->data['Site']['site_no'];?>
                </td>
            </tr>
            <?php endif; ?>
            <tr>
                <td width="120px"><?php echo $form->label('Site.name', 'Site name') ?></td>
                <td>
                    <?php echo $form->text('Site.name')?>
                </td>
            </tr>
        </table>
    </fieldset>
    <fieldset>
        <legend>Site Address</legend>
        <table style="width: 600px">
            <tbody>
                <tr>
                    <td class="top"><?php echo $form->label("Site.contract", 'Contract') ?></td>
                    <td colspan="3"><?php echo $form->text('Site.contract', array('class' => 'wide')) ?></td>
                </tr>
                <tr>
                    <td class="top"><?php echo $form->label("Site.address", 'Address') ?></td>
                    <td colspan="3"><?php echo $form->textarea('Site.address', array('rows' => 2, 'cols' => 50, 'class' => 'wide')) ?></td>
                </tr>
                <tr>
                    <td><?php echo $form->label("Site.province_id", 'Province') ?></td>
                    <td width="200px"><?php echo $form->select("Site.province_id", $provinces) ?> </td>
                    <td width="120px"><?php echo $form->label("Site.zipcode", 'Zipcode') ?></td>
                    <td><?php echo $form->text("Site.zipcode", array('size'=>5,'maxlength'=>5)) ?></td>
                </tr>
                <tr>
                    <td><?php echo $form->label("Site.tel", 'Tel.') ?></td>
                    <td><?php echo $form->text("Site.tel") ?></td>
                    <td><?php echo $form->label("Site.fax", 'Fax') ?></td>
                    <td><?php echo $form->text("Site.fax") ?></td>
                </tr>
            </tbody>
        </table>
    </fieldset>
    <fieldset>
        <legend>Site User Priviledges</legend>
        <table style="width: 600px">
            <tbody>
                <tr>
                    <td width="150px"><?php echo $form->label('Site.can_reserve_stock_out', 'Reserve Product'); ?></td>
                    <td>
                        <?php echo $form->checkbox('Site.can_reserve_stock_out'); ?> Yes/No
                    </td>
                    <td width="150px"><?php echo $form->label('Site.have_cost_center', 'Cost Center'); ?></td>
                    <td>
                        <?php echo $form->checkbox('Site.have_cost_center'); ?> Yes/No
                    </td>
                </tr>
                <tr>
                    <td>
                        <?php echo $form->label('Site.required_site_user', 'Required Site User'); ?><br />
                        <span class="caption">(When Stock out.)</span>
                    </td>
                    <td colspan="3">
                        <?php echo $form->checkbox('Site.required_site_user'); ?> Yes/No
                    </td>
                </tr>
            </tbody>
        </table>
    </fieldset>
    <?php echo $form->end(); ?>
    <br />
    <?php if ($mode == 'edit') : ?>
    <div id="tabSiteInfo<?php echo $this->data['Site']['id']; ?>">
        <ul>
            <?php if ($this->data['Site']['have_cost_center']== true) : ?>
            <li><?php echo $html->link('Cost Center', array('controller' => 'its_customers', 'action' => 'display_site_cost_center', $this->data['Site']['id'])); ?></li>
            <li><?php echo $html->link('Site User', array('controller' => 'its_customers', 'action' => 'display_site_user', $this->data['Site']['id'])); ?></li>
            <?php endif; ?>
            <li><?php echo $html->link('Location', array('controller' => 'its_customers', 'action' => 'display_cust_locations', $this->data['Site']['id'])); ?></li>
            <li><?php echo $html->link('Return to Inventory Reasons', array('controller' => 'its_customers', 'action' => 'display_cust_stock_out_return_reasons', $this->data['Site']['id'])); ?></li>
        </ul>
    </div>
    <script type="text/javascript">
        $j(function() {
            $j("#tabSiteInfo<?php echo $this->data['Site']['id']; ?>").tabs(tab_options);
        });
    </script>
    <?php endif; ?>
</div>